#include <pthread.h>
#include <rclcpp/rclcpp.hpp>

class InputFromTerminalNode : public rclcpp::Node {
public:
  InputFromTerminalNode() : Node("input_from_terminal") {
    RCLCPP_INFO(this->get_logger(), "InputFromTerminalNode has been created");
    input_str_ = this->declare_parameter("input_str", "");
    RCLCPP_INFO(this->get_logger(), "Input string: %ld", pthread_self());
  }
  void getFromTerminal() {
    // while (1) {
    //   RCLCPP_INFO(this->get_logger(), "Waiting for input from terminal");
    //   std::string input_str;
    //   std::cout << "Please input a string: " << std::endl;
    //   std::cin >> input_str;
    //   if (input_str == "exit")
    //     break;

    RCLCPP_INFO(this->get_logger(), "Input string: %s", input_str_.c_str());
    if (input_str_ == "exit") {
      RCLCPP_INFO(this->get_logger(), "Exiting program");
      exit(0);
    }
    // }
  }

private:
  std::string input_str_;
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  auto node = std::make_shared<InputFromTerminalNode>();
  node->getFromTerminal();
  rclcpp::spin(node);
  rclcpp::shutdown();
  return 0;
}